package dbUnit;
import java.sql.*;

public class MysqlConnect {

	public String url;
	public String dbName;
	public String driver;
	public String userName;
	public String password;

	public Connection conn;
	public Statement stat;
	public String selectQuery;
	public ResultSet results;

	public MysqlConnect() {

		url = "jdbc:mysql://50.56.207.18:3306/";
		dbName = "ai_dialog";
		driver = "com.mysql.jdbc.Driver";
		userName = "ai_user";
		password = "open123";

		conn = null;
	}

	public void dbConnect() {

		try {
			Class.forName(this.driver).newInstance();
			this.conn = DriverManager.getConnection(this.url + this.dbName,
					this.userName, this.password);
			//System.out.println("Connected to the database");
		} catch (Exception e) {
			System.out.println("Error in Database Connection");
			e.printStackTrace();
		}

	}

	public void dbClose() {
		try {
			this.conn.close();
			//System.out.println("Disconnected from database");
		} catch (Exception e) {
			System.out.println("Error in Database DisConnection");
		}
	}

	public String executeQuery(String query) {

		String temp="";
		try {
			this.dbConnect();

			// create statement handle for executing queries
			Statement stat = this.conn.createStatement();
			// query to select all of the data from a table
			String selectQuery = query;
			// get the results
			ResultSet results = stat.executeQuery(selectQuery);
			
			
			// output the results
			while (results.next()) {
				
				//
				
			}

			this.dbClose();
		} catch (Exception e) {
			System.out.println("Error in xecuteQuery");
		} finally {
			this.dbClose();
		}
		
		return temp;

	}

}